library(RColorBrewer)
library(ggplot2)
library(gganimate)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(gifski)
library(png)
library(sp)
library(raster)
##
## Attaching package: 'raster'
## The following object is masked from 'package:dplyr':
##
## select
## The following object is masked from 'package:gganimate':
##
## animate
library(rgdal)
## rgdal: version: 1.4-4, (SVN revision 833)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 2.4.2, released 2019/06/28
## Path to GDAL shared files: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/gdal
## GDAL binary built with GEOS: FALSE
## Loaded PROJ.4 runtime: Rel. 5.2.0, September 15th, 2018, [PJ_VERSION: 520]
## Path to PROJ.4 shared files: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/rgdal/proj
## Linking to sp version: 1.3-1
library(tmap)
library(tmaptools)
library(spdep)
## Loading required package: spData
## To access larger datasets in this package, install the spDataLarge
## package with: `install.packages('spDataLarge',
## repos='https://nowosad.github.io/drat/', type='source')`
## Loading required package: sf
## Linking to GEOS 3.7.2, GDAL 2.4.2, PROJ 5.2.0
library(rgeos)
## rgeos version: 0.5-2, (SVN revision 621)
## GEOS runtime version: 3.7.2-CAPI-1.11.2
## Linking to sp version: 1.3-1
## Polygon checking: TRUE
library(geosphere)
library(spatstat)
## Loading required package: spatstat.data
## Loading required package: nlme
##
## Attaching package: 'nlme'
## The following object is masked from 'package:raster':
##
## getData
## The following object is masked from 'package:dplyr':
##
## collapse
## Loading required package: rpart
##
## spatstat 1.61-0 (nickname: 'Puppy zoomies')
## For an introduction to spatstat, type 'beginner'
##
## Note: spatstat version 1.61-0 is out of date by more than 4 months; we recommend upgrading to the latest version.
##
## Attaching package: 'spatstat'
## The following object is masked from 'package:geosphere':
##
## perimeter
## The following objects are masked from 'package:raster':
##
## area, rotate, shift
library(maptools)
## Checking rgeos availability: TRUE
library(knitr)
library(kableExtra)
##
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
##
## group_rows
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:raster':
##
## select
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(corrplot)
## corrplot 0.84 loaded
library(shinyjs)
##
## Attaching package: 'shinyjs'
## The following object is masked from 'package:rgeos':
##
## show
## The following object is masked from 'package:raster':
##
## click
## The following object is masked from 'package:sp':
##
## show
## The following objects are masked from 'package:methods':
##
## removeClass, show
library(ggalt)
## Registered S3 methods overwritten by 'ggalt':
## method from
## grid.draw.absoluteGrob ggplot2
## grobHeight.absoluteGrob ggplot2
## grobWidth.absoluteGrob ggplot2
## grobX.absoluteGrob ggplot2
## grobY.absoluteGrob ggplot2
Bar graph of solar energy generation by continent from 2000-2018.
Source: BP Statistical Review (2018), accessed via https://ourworldindata.org/renewable-energy. Data was downloaded as an Excel spreadsheet, and preprocessed by creating a pivot table with entities as rows and years as columns, and inserting a slicer to include only the years 2000-2018 and only the 6 inhabited continents.
# Read in preprocessed csv file.
sol3=read.csv("/Users/ngigot/Desktop/GEOG456/cleanedsolargenerationtable.csv")
# Create bar plot of solar output by year and by continent. Set year as x axis, set solar output as y axis. Fill columns categorically by continent. Label axes, set theme, set color palette. Give bar plot a title.
plot1=ggplot(sol3, aes(x=Year, y=SolarOutput))+geom_col(aes(fill=Continent),width=.7) + labs(y="Solar Energy Generation (TWh)") + theme_minimal() + scale_fill_brewer(palette="Set1") + labs(title = "Global Solar Energy Growth")
# Call plot.
plot1
Line graph of solar energy generation by continent from 2000-2018.
Source: BP Statistical Review (2018), accessed via https://ourworldindata.org/renewable-energy. Data was downloaded as an Excel spreadsheet, and preprocessed by creating a pivot table with entities as rows and years as columns, and inserting a slicer to include only the years 2000-2018 and only the 6 inhabited continents.
# Create line graph of solar output by year and by continent. Set year as x axis, set solar output as y axis. Color lines categorically by continent. Label axes, set theme, set color palette. Give line graph a title.
plot2=ggplot(data=sol3, aes(x=Year, y=SolarOutput, group=Continent))+geom_line(aes(color=Continent))+labs(y="Solar Energy Generation (TWh)") + theme_minimal() + scale_fill_brewer(palette="Set1") + labs(title = "Global Solar Energy Growth")
# Call graph.
plot2
Animated lollipop chart of solar energy generation by continent from 2000-2018.
Source: BP Statistical Review (2018), accessed via https://ourworldindata.org/renewable-energy. Data was downloaded as an Excel spreadsheet, and preprocessed by creating a pivot table with entities as rows and years as columns, and inserting a slicer to include only the years 2000-2018 and only the 6 inhabited continents.
# Create chart of solar output by continent. Set continent as x-axis and set solar output as y-axis. Set label and color to Continent. Create points for each continent and create segments for each continent to make the lollipop chart. Give the points text. Animate the chart by setting year as the transition time and setting the easing as linear (each frame lasts the same amount of time). Set the theme and the color palette.
plot3=ggplot(sol3,
aes(x=Continent, y=SolarOutput, label=Continent, color=Continent)) +
geom_point(stat='identity',size=15) +
geom_segment(aes(
y=0,
x=Continent,
yend=SolarOutput,
xend=Continent)
) +
geom_text(color="black", size=3) +
theme(legend.position = "none") +
labs(title = "Year: {frame_time}", y="Solar Energy Generation (TWh)") + transition_time(Year) +
ease_aes('linear') + theme_minimal() + scale_fill_brewer(palette="Set2")
# Call plot.
plot3
Interactive map of solar energy generation by continent in 2018.
Source: BP Statistical Review (2018), accessed through OurWorldInData.org, and Continent Shapefile (2015) accessed via https://www.arcgis.com/home/item.html?id=5cf4f223c4a642eb9aa7ae1216a04372. Map was downloaded, unzipped, and read in as a shapefile. The preprocessed data on solar output by continent and by year was modified to include solar output as percent of total and was also modified to include Antarctica and Oceania in order to match records for the join.
# Read in continents shapefile.
continents=shapefile("/Users/ngigot/Desktop/GEOG456/continent shapefile/continent.shp")
# Read in attribute table.
map=read.csv("/Users/ngigot/Desktop/GEOG456/mapattributetable.csv")
# Create column in the attribute table for percent change in solar output between 2010 and 2018.
map$perchange=100*(map$X2018-map$X2010)/map$X2010
# Join attribute table to continents shapefile using the continent name columns as the key field.
mapcont=merge(continents, map, by.x="CONTINENT", by.y="Continent")
# Set tmap mode to interactive viewing.
tmap_mode("view")
## tmap mode set to interactive viewing
# Create interactive map using an ESRI basemap, make the map a choropleth map by assigning to each continent the value of its solar output as a percent of the world's total solar output. Give the legend a title, set the style, set the palette, adjust the border settings. Name the polygons based on their continent name. Set and name the pop-up variables to show solar generation, solar generation as a percent of total, and solar generation as a percent change from 2010 to 2018. Insert a scalebar and adjust the legend settings.
map1=tm_shape(mapcont) + tm_basemap("Esri.WorldGrayCanvas") + tm_polygons("X2018", title = "Solar Generation (% of Total)", style = "pretty", palette = "Greens", alpha = 1, border.col = "gray0", border.alpha = 0.6, id="CONTINENT", popup.vars = c("Solar Generation (% of Total)" = "X2018", "Solar Generation (TWh)" = "X2018Total", "Solar Generation (% Change 2010-2018)" = "perchange")) + tm_tiles("CartoDB.PositronOnlyLabels") + tm_scale_bar() + tm_view(view.legend.position = c("right", "bottom")) + tm_layout(legend.outside=TRUE) # Call the map.
map1
Scatter plots of the number of patents and investment in various renewable energy technologies between 2004 and 2016.
Source: International Renewable Energy Agency (2016), accessed through https://ourworldindata.org/renewable-energy. Two spreadsheets were downloaded, one on the number of patents by year by technology and one on the investment by year by technology. The data was preprocessed by joining the spreadsheets together and inserting a pivot table with columns for technology, year, investment, and number of patents. Another spreadsheet was created with the logarithm of the investment and number of patent values.
# Read in the log investment and patent csv file.
patents=read.csv("/Users/ngigot/Desktop/GEOG456/patentsinvestments1.csv")
# Read in the non-log investment and patent csv file.
patents2=read.csv("/Users/ngigot/Desktop/GEOG456/patentsinvestments2.csv")
# Create scatter plots of the log investment and patent data. Set log patent values as the x-axis and the log investment values as the y-axis. Categorize the plots by giving the different technologies different colors. Create a trend line using a linear model, add smoothed conditional means to better show pattern. Wrap the sequence of plots to save space. Set theme, set palette, give the plots a title and label the axes.
plot4=ggplot(patents, aes(Patents, Investment, col=Technology, frame = Year)) +
geom_point() +
geom_smooth(aes(group = Technology),
method = "lm",
show.legend = FALSE) +
facet_wrap(~Technology, scales = "free") + theme_minimal() + scale_fill_brewer(palette="Set1") + labs(title = "Renewable Energy Innovation and Investment (2004-2016)", x="Log of Number of Patents Filed ", y="Log of USD Invested")
# Call plot.
plot4
Animated scatter plot of the number of patents and investment in various renewable energy technologies between 2004 and 2016.
Source: International Renewable Energy Agency (2016), accessed through https://ourworldindata.org/renewable-energy. Two spreadsheets were downloaded, one on the number of patents by year by technology and one on the investment by year by technology. The data was preprocessed by joining the spreadsheets together and inserting a pivot table with columns for technology, year, investment, and number of patents.
# Create a scatter plot using the non-log investment and patent data. Set the number of patents as the x-axis and the investment values as the y-axis. Categorize the plots by giving the different technologies different colors. Animate the chart by setting year as the transition time and setting the easing as linear (each frame lasts the same amount of time). Set the theme and the color palette.
plot5=ggplot(patents2, aes(Patents, Investment, frame=Year, col=Technology, size=20)) + geom_point() + labs(title = "Year: {frame_time}", y="USD Invested", x="Number of Patents Filed") + transition_time(Year) + ease_aes('linear') + theme_minimal() + scale_fill_brewer(palette="Set2")
# Call plot.
plot5